﻿tripPoster = {
    addAccount: function () {
        $.ajax({
            url: '/Account/AccountAdder',
            type: 'GET',
            success: function (e) {
                var list = $("#accountList");
                list.append(e);
            }
        });
    },
    removeAccount: function (e) {
        var ad = document.getElementById(e);
        ad.parentNode.removeChild(ad);
    },
    submit: function () {
        var accounts = Array();

        var accountList = $(".accountSelector");
        for (var i = 0; i < accountList.length; i++) {
            var ddl = $(".accountSelector select:eq(" + i + ")");
            var text = $(".accountSelector input[type='text']:eq(" + i + ")");

            accounts.push({
                Id: $(ddl).val(),
                Percentage: $(text).val()
            });
        }

        var postData = {
            AssignmentId: $("#AssignmentId").val(),
            StartLocation: $("#StartLocation").val(),
            StartDate: $("#StartDate").val(),
            EndLocation: $("#EndLocation").val(),
            EndDate: $("#EndDate").val(),
            TransportationMode: $("#TransportationMode").val(),
            TransportationCost: $("#TransportationCost").val(),
            Accounts: accounts
        }

        $("form")[0].submit(postData, function (e) {
            alert("Hi");
        });
        //$.post('/Assignment/AddTrip', postData);
    }
}